<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<script type="text/javascript" src="../js/jquery-1.8.3.js"></script>
		<script type="text/javascript" src="../js/easyui/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="../js/easyui/locale/easyui-lang-zh_CN.js"></script>
		<script type="text/javascript" src="../js/ztree/jquery.ztree.all-3.5.js" charset="UTF-8"></script>
		<link rel="stylesheet" href="../js/easyui/themes/default/easyui.css" />
		<link rel="stylesheet" href="../js/easyui/themes/icon.css" />
		<link rel="stylesheet" href="../js/ztree/zTreeStyle.css" />
		<script type="text/javascript">
			$(function() {
				var setting = {
					data: {
						simpleData: {
							enable: true
						}
					},
					callback: {
						onClick: function(event, treeId, treeNode, clickFlag) {
							var content = "<div style='height: 100%; width: 100%;overflow: hidden;'><iframe scrolling='auto' src='" + treeNode.page + "' style='width: 100%;height: 100%;border: 0;'></iframe></div>";
							if(treeNode.page != undefined && treeNode.page != "") {
								if($("#tabs").tabs('exists', treeNode.name)) {
									$("#tabs").tabs('select', treeNode.name);
								} else {
									$("#tabs").tabs('add', {
										title: treeNode.name,
										content: content,
										closable: true
									});
								}
							}
						}
					}
				};
				var treeNode = [{
						id: 1,
						pId: 0,
						name: "父节点一"
					},
					{
						id: 2,
						pId: 0,
						name: "父节点二"
					},
					{
						id: 11,
						pId: 1,
						name: "百度",
						page: "http://www.baidu.com"
					},
					{
						id: 12,
						pId: 1,
						name: "github",
						page: "https://github.com/"

					},
					{
						id: 21,
						pId: 2,
						name: "子节点二一"
					},
					{
						id: 22,
						pId: 2,
						name: "子节点二二"
					}
				];
				$.fn.zTree.init(
					$("#baseMenu"),
					setting,
					treeNode
				);

				$("#tabs").tabs({
					onContextMenu: function(e, title, index) {
						e.preventDefault();
						$("#closeMenu").menu('show', {
							left: e.pageX,
							top: e.pageY
						});
					},
				});

				//为每个菜单绑定点击事件
				//关闭选中的标签
				$("#closeThis").click(function() {
					//获取选中的标签索引
					var tab = $('#tabs').tabs('getSelected');
					var index = $('#tabs').tabs('getTabIndex', tab);
					$("#tabs").tabs("close", index);
				});
				//关闭选中标签之外的标签
				$("#closeOthers").click(function() {
					//获取所有标签
					var tabs = $("#tabs").tabs("tabs");
					var length = tabs.length;
					//获取选中标签的索引
					var tab = $('#tabs').tabs('getSelected');
					var index = $('#tabs').tabs('getTabIndex', tab);
					//关闭选中标签之前的标签
					for(var i = 0; i < index; i++) {
						$("#tabs").tabs("close", 0);
					}
					//关闭选中标签之后的标签
					for(var i = 0; i < length - index - 1; i++) {
						$("#tabs").tabs("close", 1);
					}
				});
				//关闭所有标签
				$("#closeAll").click(function() {
					var tabs = $("#tabs").tabs("tabs");
					var length = tabs.length;
					for(var i = 0; i < length; i++) {
						$("#tabs").tabs("close", 0);
					}
				});
			});
		</script>
	</head>

	<body class="easyui-layout">

		<div data-options="region:'north', title:'传智管理系统' " style="height: 100px;"></div>
		<div data-options="region:'west',title:'菜单导航'" style="width: 180px;">
			<div class="easyui-accordion" data-options="fit:true">
				<div data-options="title:'基础菜单'">
					<ul class="ztree" id="baseMenu"></ul>
				</div>
				<div data-options="title:'系统菜单'">菜单二</div>
			</div>
		</div>
		<div data-options="region:'center'">
			<div id="tabs" class="easyui-tabs" data-options="fit:true,closable:'true'">
			</div>
		</div>
		<div data-options="region:'east'" style="width: 100px;">东部区域</div>
		<!--关闭选项卡-->
		<div class="easyui-menu" id="closeMenu" style="width: 100px;">
			<div id="closeThis">关闭当前窗口</div>
			<div id="closeOthers">关闭其它窗口</div>
			<div class="menu-sep"></div>
			<div data-options="iconCls:'icon-cancel'" id="closeAll">关闭所有窗口</div>
		</div>
	</body>

</html>